Skip to main content

Workflow Condition Template

The Workflow Condition template demonstrates how a BindAI workflow can make a runtime decision and continue execution through one of two configured paths. A ConditionNode evaluates a predicate against the workflow context. Depending on whether the predicate returns True or False, the node adds the configured true or false node to the workflow execution queue. This template introduces conditional branching into BindAI workflows.

Purpose

This template demonstrates how to:
  • Add a ConditionNode to a workflow
  • Evaluate runtime workflow context
  • Define a true branch
  • Define a false branch
  • Route execution dynamically
  • Use workflow variables when implementing predicates
It extends the basic sequential workflow model with a decision point.

Workflow Structure

A conditional workflow can be represented conceptually as:
The ConditionNode itself does not contain the branch node implementations. Instead, it stores the identifiers of the nodes to execute when the predicate evaluates to True or False.

ConditionNode

The condition implementation is:
The predicate has the following conceptual signature:
This means the predicate receives the current workflow context and must return a Boolean value. For example:
The condition can then be created with:

Defining the Branches

The true and false branches are configured explicitly.
Both methods return the condition node itself, allowing chained configuration:
The condition stores the IDs of the configured nodes.

Execution Flow

When the workflow executor reaches a ConditionNode, it calls:
The condition evaluates its predicate:
The selected node is added to the workflow execution queue. The workflow executor then continues processing nodes from that queue.

Decision Logic

The condition itself does not require a specific business rule. The predicate determines the decision. For example:
The condition can then route execution based on that value:
or:
The predicate can inspect any information available through the workflow context.

Workflow Context

The predicate receives the workflow context:
This provides access to the workflow’s runtime state. A common pattern is to inspect workflow variables:
A previous node may populate the variable:
The condition can then use that value to determine the next execution path. The exact variables available depend on the nodes and application logic in the workflow.

Example

Suppose a previous node determines whether a request should be approved.
The resulting execution conceptually looks like:
If approved is True, the approval node is queued. If approved is not True, the rejection node is queued.

Branch Configuration

A true branch is configured with:
A false branch is configured with:
Both branches are optional at the ConditionNode level. If the predicate evaluates to True but no true node has been configured, no true-branch node is added to the execution queue. Likewise, if the predicate evaluates to False but no false node has been configured, no false-branch node is added. For predictable workflows, configure the branch paths that the workflow is expected to use.

Branching Example

A common approval workflow might look like:
The condition separates the decision from the actions performed after the decision. This allows the workflow structure to express the business process explicitly.

Agent Integration

An agent can produce information that a later condition evaluates. For example:
The agent and condition have separate responsibilities:
  • The agent performs AI-driven work.
  • The workflow condition evaluates runtime state.
  • The selected branch determines what executes next.
The exact mechanism used to populate variables depends on the agent node and surrounding workflow implementation. A ConditionNode itself does not perform AI reasoning.

Conditions and Workflow Orchestration

Conditions are useful when a workflow needs deterministic orchestration around runtime data. For example:
The decision is represented explicitly in the workflow rather than being hidden inside a prompt. This can make workflow behavior easier to inspect and test.

Common Use Cases

Conditional workflows can be useful for:
  • Approval decisions
  • Validation results
  • Eligibility checks
  • Request routing
  • Escalation decisions
  • Status-based processing
  • Threshold checks
  • Classification results
  • Business-rule evaluation
The predicate can implement the rule appropriate for the workflow.

Predicate Design

A predicate should return a Boolean value:
Avoid making the predicate responsible for performing large amounts of workflow work. A useful separation is:
The condition’s responsibility is to make the routing decision.

Condition vs Prompt Logic

Conditions are useful for deterministic workflow routing. This does not mean prompts should never contain reasoning. Rather, ConditionNode provides a clear mechanism for deterministic orchestration around runtime state.

Combining Conditions

Multiple conditions can be used in the same workflow. For example:
Each condition evaluates its own predicate and queues the configured branch node. Complex decision trees should be kept understandable and tested across their possible paths.

Testing Both Branches

A condition should be tested with context values that exercise both outcomes. For example:
Test with:
and:
This verifies that both branch paths are configured correctly. It is also useful to test the behavior when an expected variable is missing.

Current Implementation Details

The current ConditionNode implementation:
maintains:
The branch methods store node IDs:
During execution:
The selected branch node ID is appended to:
The condition returns the workflow context after making the routing decision.

Important Boundaries

No built-in Start Node

A condition workflow does not require a special StartNode. The workflow’s first added node becomes its starting node.

No built-in End Node

A condition workflow does not require a special EndNode. The workflow completes according to the normal workflow executor rules after the execution queue is exhausted or another terminal execution condition occurs.

The predicate receives the context

The condition does not receive a single variable value automatically. The predicate receives the complete WorkflowContext and decides what information to inspect.

Branches are node references

when_true() and when_false() store the identifiers of the selected nodes. They do not execute those nodes immediately. The workflow executor processes the queued node afterward.

Missing branches are possible

A true or false branch may be left unset. In that case, the corresponding branch does not add a node to the execution queue.

Best Practices

  • Keep predicates focused on the routing decision.
  • Read runtime data from the workflow context.
  • Use descriptive node identifiers.
  • Configure both branches when both outcomes are meaningful.
  • Test both true and false outcomes.
  • Test missing or unexpected context values.
  • Keep complex business logic outside the condition when possible.
  • Use multiple conditions carefully so the workflow remains understandable.
  • Prefer explicit workflow routing over hidden orchestration logic.

Related Templates

The condition pattern builds on the basic workflow model introduced in:
  • 08.1 workflow-basic.md
It can be combined with:
  • 08.3 workflow-loop.md
  • 08.4 workflow-parallel.md
  • 08.5 workflow-human.md
  • 08.6 workflow-retry.md
  • 08.7 workflow-timeout.md
  • 08.8 workflow-schedule.md
Conditions are particularly useful when combined with other workflow capabilities to create decision-driven automation.

Summary

The Workflow Condition template introduces deterministic branching into BindAI workflows. The essential pattern is:
A ConditionNode receives a predicate operating on the workflow context. The predicate returns True or False, and the condition adds the corresponding configured node to the workflow execution queue. This provides an explicit mechanism for routing workflow execution based on runtime state.